<template>
  <div></div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  components: {},
  data() {
    return {
      arr: [{ id: '', count: 0, key: this.$quinn.guid() }],
      formKey: this.$quinn.guid(),
      modify: 'add',
      disabledType: false,
      dialogVisible: false,
      row: {},
      form: {},
      ref: 'form',
      labelWidth: '100px',
      inline: false,
      labelPosition: 'top',
      fileList: [],
    }
  },
  computed: {
    ...mapState(['token']),
    dialogOpts() {
      const {
        dialogTitle = '',
        dialogTop: top = '12vh',
        title,
        dialogWidth: width = '500px',
      } = this
      return {
        title: dialogTitle || title,
        'close-on-click-modal': false,
        width,
        top,
      }
    },
    formOpts() {
      //   console.log('[ formOpts--- ] >', this)
      const {
        form,
        formKey: key,
        ref,
        labelWidth,
        inline,
        labelPosition,
      } = this
      return {
        form,
        key,
        ref,
        inline,
        labelWidth,
        labelPosition,
      }
    },
    formEvent() {
      return {
        submit: this.onSubmit,
      }
    },
    title() {
      return this.modify === 'add' ? '新增' : '编辑'
    },
  },
  watch: {
    '$store.state.directoryMap': function () {
      if (this.form.directoryId) {
        this.form.directoryId.items = this.getDirectoryItem()
        this.formKey = this.$quinn.guid()
      }
    },
  },
  methods: {
    onChange(res, k = '') {
      this['fileList' + k] = res
    },
    getDirectoryItem() {
      const selectMap = this.$store.state.directoryMap
      return Object.keys(selectMap).map((value) => ({
        value,
        label: selectMap[value],
      }))
    },
    onConfirm() {
      const form = this.$refs.form
      form.submit()
    },

    submitDoneMsg(msg = '操作成功') {
      // this.$message.success(msg);
      this.fileList = []
      this.arr = [{ id: '', count: 0, norms: '', key: this.$quinn.guid() }]
      this.submitDone()
    },
    submitDone() {
      this.dialogVisible = false
      setTimeout(() => {
        this.$emit('change')
      }, 150)
    },
    showDialog(modify = 'add', row = {}) {
      this.dialogVisible = true
      this.row = row
      this.modify = modify || 'add'
      for (const key in this.form) {
        let defValue = ''
        if (Array.isArray(this.form[key].value)) defValue = []
        if (Object.hasOwnProperty.call(row, key))
          this.form[key].value = row[key] || defValue
        else this.form[key].value = defValue
      }
      this.formKey = this.$quinn.guid()
    },
  },
}
</script>

<style lang="less" scoped></style>
